package testtiles;

import butines.game.AbstractState;


public class UnitWaitState extends AbstractState<Unit> {

	private static final UnitWaitState instance = new UnitWaitState();

	public static UnitWaitState getInstance() {
		return instance;
	}
	
	@Override
	public void enter(Unit unit) {
		float waitCount = (float)(.2f + Math.random()) %.7f;
		unit.getAnimationSet().getStay().play();
		unit.setWaitCount(waitCount);
		unit.setSpeed(0);
	}
	
	@Override
	public void leave(Unit unit) {
		
	}

	@Override
	public void execute(Unit unit) {
		if (unit.getWaitCount() == 0) {
			unit.getStateMachine().revertToPreviousState();
		}
	}
	
}
